/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.shop.web.cate_gory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.shop.entity.cate_gory.Cate_Gory;
import com.thinkgem.jeesite.modules.shop.service.cate_gory.Cate_GoryService;

/**
 * 分类Controller
 * @author xfj
 * @version 2019-05-15
 */
@Controller
@RequestMapping(value = "${adminPath}/shop/cate_gory/cate_Gory")
public class Cate_GoryController extends BaseController {

	@Autowired
	private Cate_GoryService cate_GoryService;
	
	@ModelAttribute
	public Cate_Gory get(@RequestParam(required=false) String id) {
		Cate_Gory entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = cate_GoryService.get(id);
		}
		if (entity == null){
			entity = new Cate_Gory();
		}
		return entity;
	}
	
	@RequiresPermissions("shop:cate_gory:cate_Gory:view")
	@RequestMapping(value = {"list", ""})
	public String list(Cate_Gory cate_Gory, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<Cate_Gory> page = cate_GoryService.findPage(new Page<Cate_Gory>(request, response), cate_Gory); 
		model.addAttribute("page", page);
		return "modules/shop/cate_gory/cate_GoryList";
	}

	@RequiresPermissions("shop:cate_gory:cate_Gory:view")
	@RequestMapping(value = "form")
	public String form(Cate_Gory cate_Gory, Model model) {
		model.addAttribute("cate_Gory", cate_Gory);
		return "modules/shop/cate_gory/cate_GoryForm";
	}

	@RequiresPermissions("shop:cate_gory:cate_Gory:edit")
	@RequestMapping(value = "save")
	public String save(Cate_Gory cate_Gory, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, cate_Gory)){
			return form(cate_Gory, model);
		}
		cate_GoryService.save(cate_Gory);
		addMessage(redirectAttributes, "保存分类成功");
		return "redirect:"+Global.getAdminPath()+"/shop/cate_gory/cate_Gory/?repage";
	}
	
	@RequiresPermissions("shop:cate_gory:cate_Gory:edit")
	@RequestMapping(value = "delete")
	public String delete(Cate_Gory cate_Gory, RedirectAttributes redirectAttributes) {
		cate_GoryService.delete(cate_Gory);
		addMessage(redirectAttributes, "删除分类成功");
		return "redirect:"+Global.getAdminPath()+"/shop/cate_gory/cate_Gory/?repage";
	}

}